﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.Model;
using OgilvyOne.BLL;
using OgilvyOne.Utility;


public partial class admin_infomation_info_map_detail : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!isExist(layerid, "1,2,3,24,104"))
        {
            log.Visible = false;
        }
        if (!IsPostBack)
        {
            this.RadioButton1.Checked = true;
            int aid = int.Parse(Request.Params["aid"]);
            CmsArticleModel cm = new CmsArticleBll().GetCmsArticleModel(aid);
            this.headers.Text = "当前位置：" + cm.Title + "&nbsp;&nbsp;<img src='../images/subnav_dot.gif' />&nbsp;&nbsp;地图详情";
            if (Request.Params["mid"] != null && Request.Params["mid"] != "")
            {
                int mid = int.Parse(Request.Params["mid"]);
                CmsArticleMapModel camm = new CmsArticleMapBll().GetMap(" MAP_ID=" + mid);
                this.txtmapname.Text = camm.MapName;
                this.txtmaplat.Text = camm.MapLat;
                this.txtmaplog.Text = camm.MapLog;
                this.txtmapcontent.Text = camm.MapContent;
                this.ordernum.Text = camm.Ordernum.ToString();
                if (camm.State == 1)
                {
                    this.RadioButton1.Checked = true;
                }
                else {
                    this.RadioButton2.Checked = true;
                }
            }
        }

    }
    protected void Button_Click(object sender, EventArgs e)
    {
        string user = GetSessionUsersModel().Username.ToString();
        int aid = int.Parse(Request.Params["aid"]);
        if (Request.Params["mid"] != null && Request.Params["mid"] != "")
        {
            int mid = int.Parse(Request.Params["mid"]);
            CmsArticleMapModel camm = new CmsArticleMapModel();
            camm.MapId = mid;
            camm.MapName = this.txtmapname.Text;
            camm.MapLat = this.txtmaplat.Text;
            camm.MapLog = this.txtmaplog.Text;
            camm.MapContent = this.txtmapcontent.Text;
            camm.Ordernum = ordernum.Text != "" ? int.Parse(ordernum.Text) : 0;
            if (this.RadioButton1.Checked == true) { camm.State = 1; } else { camm.State = 0; }
            bool bl = new CmsArticleMapBll().Update(camm);
            if (bl)
            {
                new CmsArticleBll().UpdateAudit(aid, GetSessionUsersModel().Username);
                insertLog("修改文章地图:" + camm.MapName);
                Response.Write("<script>alert('修改成功!')</script>");
            }
            else
            {
                Response.Write("<script>alert('修改失败!')</script>");
            }
        }
        else
        {
            CmsArticleMapModel camm = new CmsArticleMapModel();
            camm.MapName = this.txtmapname.Text;
            camm.MapLat = this.txtmaplat.Text;
            camm.MapLog = this.txtmaplog.Text;
            camm.MapContent = this.txtmapcontent.Text;
            camm.ArticleId = aid;
            if (this.RadioButton1.Checked == true) { camm.State = 1; } else { camm.State = 0; }
            camm.AddUser=user;
            int t = new CmsArticleMapBll().Add(camm);
            new CmsArticleBll().UpdateAudit(aid, GetSessionUsersModel().Username);
            insertLog("增加文章地图:" + camm.MapName);
        }
        Response.Redirect("info_map_list.aspx?aid=" + Request.Params["aid"] + "&layerid=" + Request.Params["layerid"]);
    }
}
